package com.javaee.controller.admin;


import com.javaee.BeforeBaseController;
import com.javaee.entity.User;

import com.javaee.service.admin.UserService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


import java.io.IOException;

@Controller
@RequestMapping("/user")
public class UserController extends BeforeBaseController {
    @Autowired
    private UserService userService;

    @RequestMapping("/toAddUser")
    public String toAddUser(User user, Model model) {

        return userService.toAddUser(user, model);
    }

    @RequestMapping("/addUser")
    public String addUser(@ModelAttribute("user") User user, HttpServletRequest request) throws IllegalStateException, IOException {
        System.out.println("病人信息为"+user);
        return userService.addUser(user, request);
    }

    @RequestMapping("/selectAllUsersByPage")
    public String selectAllUsersByPage(Model model, int currentPage) {
        return userService .selectAllUsersByPage(model, currentPage);
    }

    @RequestMapping("/detail")
    public String detail(Model model, Integer id) {
        return userService.detail(model, id);
    }

    @RequestMapping("/delete")
    @ResponseBody
    public String delete(Integer id) {
        return userService.delete(id);
    }

    @RequestMapping("/toUpdate")
    public String toUpdate(Model model, Integer id) {
        return userService.toUpdate(model, id);
    }

    @RequestMapping("/update")
    public String update(User user, @RequestParam(name = "people",required = false) String people, HttpServletRequest request) throws Exception {
        System.out.println("修改的病人信息："+user );
        System.out.println(people);
        return userService.update(user,people, request);
    }











}
